package com.mla.fastdfs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.mla.fastdfs.mapper.GroupMapper;
import com.mla.fastdfs.pojo.Group;
import com.mla.fastdfs.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements GroupService {
    @Autowired
    private GroupMapper groupMapper;

    @Override
    public List<Group> getList(Group record) {
        LambdaQueryWrapper<Group> queryWrapper = new QueryWrapper<Group>().lambda()
                .eq(StringUtil.isNotEmpty(record.getGroupCore()), Group::getGroupCore, record.getGroupCore())
                .like(StringUtil.isNotEmpty(record.getGroupName()), Group::getGroupName, record.getGroupName());
        return groupMapper.selectList(queryWrapper);
    }

    @Override
    public PageInfo<Group> pageList(Group record, Integer pageNo, Integer pageSize) {
        LambdaQueryWrapper<Group> queryWrapper = new QueryWrapper<Group>().lambda()
                .eq(StringUtil.isNotEmpty(record.getGroupCore()), Group::getGroupCore, record.getGroupCore())
                .like(StringUtil.isNotEmpty(record.getGroupName()), Group::getGroupName, record.getGroupName());
        PageHelper.startPage(pageNo, pageSize);
        List<Group> list = groupMapper.selectList(queryWrapper);
        return new PageInfo<>(list);
    }
}
